#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QApplication>
#include <QQmlEngine>
#include <QWindow>
#include <QWidget>
#include <QPushButton>
#include <QDebug>
#include "MyForm.h"

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    // if you want to use qwidget, must use QApplication
    QApplication app(argc, argv);

    // QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    engine.load(url);
    if (engine.rootObjects().isEmpty())
    {
        qDebug() << "Load qrc:/main.qml error!";
        return -1;
    }
    QObject *qmlObj = engine.rootObjects().first();       // first QML object
    QWindow *qmlWindow = qobject_cast<QWindow *>(qmlObj); // to QWindow

    // a widget
    MyForm *myForm = new MyForm();
    if (myForm)
    {
        WId parent_HWND = qmlWindow->winId();
        myForm->setGeometry(200, 100, 300, 200);
        myForm->setStyleSheet("background-color: lightgray; color: naviy;");
        myForm->winId(); // create a win id
        myForm->setProperty("_q_embedded_native_parent_handle", QVariant(parent_HWND));
        myForm->windowHandle()->setParent(qmlWindow);
        myForm->show();
        if (myForm->isModal())
        {
            qDebug() << "model" << endl;
        }
        else
        {
            qDebug() << "not model" << endl;
        }
    }

    return app.exec();
}
